package org.dlnu.xeon.service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.dlnu.xeon.dao.UserDao;
import org.dlnu.xeon.dao.VaccinationDao;
import org.dlnu.xeon.domain.User;
import org.dlnu.xeon.domain.Vaccination;
import org.dlnu.xeon.service.VaccinationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class VaccinationServiceImpl implements VaccinationService {
    @Resource
    private VaccinationDao vaccinationDao;

    @Override
    public List<Vaccination> selectAllVac(){
        try {
            return vaccinationDao.selectAllVac();
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public Vaccination selectVacByDid(Long did) {
        try {
            return vaccinationDao.selectVacByDid(did);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public List<Vaccination> selectVacByDose(String dose) {
        try {
            return vaccinationDao.selectVacByDose(dose);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public Vaccination selectVacByBatchNumber(String batch_number) {
        try {
            return vaccinationDao.selectVacByBatchNumber(batch_number);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public List<Vaccination> selectVacByUid(Long uid) {
        try {
            return vaccinationDao.selectVacByUid(uid);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public Long insertVac(Vaccination vaccination) {
        try {
            vaccinationDao.insertVac(vaccination);
            return vaccination.getDid();
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|insertUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public Vaccination updateVac(Vaccination vaccination) {
        try {
            vaccinationDao.updateVac(vaccination);
            return vaccinationDao.selectVacByDid(vaccination.getDid());
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|updateUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public void deleteVacByDid(Long did) {
        try {
            vaccinationDao.deleteVacByDid(did);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|deleteUser] db is error. error = "+ e.toString());
        }
    }

    @Override
    public void deleteVacByUid(Long uid) {
        try {
            vaccinationDao.deleteVacByUid(uid);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|deleteUser] db is error. error = "+ e.toString());
        }
    }
}

